package com.learner.exam.controller;

import com.learner.exam.service.QuestionBankService;
import com.learner.pojo.exam.QuestionBank;
import com.learner.pojo.exam.vo.BankHaveQuestionSum;
import com.learner.pojo.exam.vo.PageResponse;
import com.learner.pojo.exam.vo.QuestionVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author linweibing
 * @date 2023-03-10 23:29
 * @description: TODO
 */
@RestController
@RequestMapping("/api/exam/question/bank")
public class QuestionBankController {

    @Autowired
    private QuestionBankService questionBankService;

    /**
     * 按类型获取提库问题总数
     *
     * @param bankName 题库名
     * @param page     page
     * @param pageSize pageSize
     * @return 结果
     */
    @GetMapping("/getBankHaveQuestionSumByType")
    public PageResponse<BankHaveQuestionSum> getBankHaveQuestionSumByType(@RequestParam(required = false) String bankName, Integer pageNo, Integer pageSize) {
        return questionBankService.getBankHaveQuestionSumByType(bankName, pageNo, pageSize);
    }

    /**
     * 根据题库id和题目类型获取题目信息 type(1单选 2多选 3判断)
     *
     * @param bankId 题库id
     * @param type   类型
     * @return 结果
     */
    @GetMapping("/getQuestionByBankIdAndType")
    public List<QuestionVo> getQuestionByBankIdAndType(Integer bankId, Integer type) {
        return questionBankService.getQuestionByBankIdAndType(bankId, type);
    }

    /**
     * 查询题目根据题库id
     *
     * @param bankId 题库id
     * @return 结果
     */
    @GetMapping("/question/list/bank/{bankId}")
    public List<QuestionVo> getQuestionByBank(@PathVariable("bankId") String bankId) {
        return questionBankService.getQuestionsByBankId(Integer.valueOf(bankId));
    }


    /**
     * 获取所有题库信息
     *
     * @return 结果
     */
    @GetMapping("/getQuestionBank")
    public List<QuestionBank> getQuestionBank() {
        return questionBankService.getAllQuestionBanks();
    }


    /**
     * 将问题加入题库
     *
     * @param questionIds 题目id列表 问题id的字符串以逗号分隔
     * @param banks       题库id列表 题库id的字符串以逗号分隔
     */
    @GetMapping("/addBankQuestion")
    public void addBankQuestion(String questionIds, String banks) {
        questionBankService.addQuestionToBank(questionIds, banks);
    }


    /**
     * 将问题从题库移除
     *
     * @param questionIds 题目id列表 问题id的字符串以逗号分隔
     * @param banks       题库id列表 题库id的字符串以逗号分隔
     */
    @GetMapping("/removeBankQuestion")
    public void removeBankQuestion(String questionIds, String banks) {
        questionBankService.removeBankQuestion(questionIds, banks);
    }

    /**
     * 删除题库并去除所有题目中的包含此题库的信息
     *
     * @param ids 题库id列表 删除题库的id字符串逗号分隔
     */
    @GetMapping("/deleteQuestionBank")
    public void deleteQuestionBank(String ids) {
        questionBankService.deleteQuestionBank(ids);
    }

    /**
     * 添加题库信息
     *
     * @param questionBank 题库信息
     */
    @PostMapping("/addQuestionBank")
    public void addQuestionBank(@RequestBody QuestionBank questionBank) {
        questionBankService.addQuestionBank(questionBank);
    }
}
